const koa = require('koa')
const static = require('koa-static')
const app = new koa()
const path = require('path')
const router = require('koa-router')()

//连接数据库
require('./database/init')


const loader = require('./routes/loader')
const search = require('./routes/search')

// //连接数据库
// ;
// (async () => {
//     await connect()

//     //第一次运行的时候取消注释，爬取数据填充数据库
//     // require('./tasks/getChina')
//     // require('./tasks/getJanpan')
// })()




app.use(static(
    path.join(__dirname, 'public')
))

router.get('/', async (ctx, next) => {
    ctx.render(index)
    await next()
})

router.use('/loader', loader.routes())
router.use('/search', search.routes())

app
    .use(router.routes())
    .use(router.allowedMethods())

// 在端口3000监听:
app.listen(3000);
console.log('app started at port 3000...');